package br.consultorio.digital.control;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import br.consultorio.digital.R;
import br.consultorio.digital.modelo.ModelAgenda;
import br.consultorio.digital.modelo.ModelMedico;

public class AgendaListar extends ListActivity implements TextWatcher {
	protected static final int VOLTAR = 1, AgendaMenu = 2,
			AgendaDataListar = 3, MedicoListar = 4;
	private EditText edtagenda;
	private int id_medico;
	private String tx_data;
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.agenda);

		Bundle extras = getIntent().getExtras();
		tx_data = extras.getString("tx_data");
		id_medico = extras.getInt("id_medico", 0);
		
		buscarAgenda(tx_data, id_medico);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Intent it = new Intent();
		it.putExtra("id_medico",id_medico);
		it.putExtra("tx_data",tx_data);
		finish();
	}

	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
		switch (v.getId()) {
		case R.idMedico.edtMedico:
			if (!edtagenda.getText().toString().equals("")) {
			//	buscarAgenda(edtagenda.getText().toString());
			} else {
				buscaTodosMedico();
			}
			break;
		}
		return false;
	}

	private void buscarAgenda(String tx_data, int id_medico) {
		ModelAgenda pModel = new ModelAgenda(this);
		pModel.tratarConsultaMedico(tx_data, id_medico);
	}

	private void buscaTodosMedico() {
		ModelMedico adModel = new ModelMedico(this);
		adModel.tratarConsultaTodos();
	}

	public void afterTextChanged(Editable s) {
	}

	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}

	public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}
}
